package com.itgm.jiayun_web_project.controller;

import com.itgm.jiayun_web_project.pojo.Result;
import com.itgm.jiayun_web_project.properties.Aliyahproperties;
import com.itgm.jiayun_web_project.utils.AliyunOSSOperator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/common")
@Slf4j
@Tag(name = "通用接口", description = "通用接口")
public class CommonController {
    @Autowired
    private AliyunOSSOperator aliy;

    @Operation(summary = "上传文件", description = "上传文件")
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {

        log.info("file:{}", file.getOriginalFilename());
        //将文件交给oss管理
        String url = aliy.upload(file.getBytes(), file.getOriginalFilename());
        log.info("url:{}", url);
        return Result.success(url);
    }
}
